from flask import Blueprint, render_template, current_app, request
from flask_jwt_extended import jwt_required, get_current_user
from extensions import db
from orms import *

about_bp = Blueprint('about', __name__)


@about_bp.route('/about/')
@jwt_required(optional=True)
def hello_world():
    # 显示登陆状态 jinjia2渲染
    current_user: UserORM = get_current_user()
    # 首页文章数据
    # page = request.args.get('page', type=int, default=1)
    # per_page = request.args.get('limit', type=int, default=10)

    # q = db.select(ArticleORM)
    # # 筛选查询
    # cid = request.args.get('cid', type=int, default=1)
    # if cid != 1:
    #     q = q.where(ArticleORM.category_id == cid)
    #     q = q.order_by(ArticleORM.id)
    # q = q.order_by(ArticleORM.create_at.desc())
    #
    # pag = db.paginate(q, page=page, per_page=per_page, error_out=False)
    #
    # article_list = pag.items
    #
    # cate_list = CategoryORM.query.all()
    # # 热门文章
    # side_q = db.select(ArticleORM).order_by(ArticleORM.clicks.desc()).limit(10)
    # click_article = db.session.execute(side_q).scalars()
    # print(click_article)
    return render_template(
        'about.html',
        current_user=current_user,
        # article_list=article_list,
        # cate_list=cate_list,
        # pag=pag,
        # click_article=click_article,
    )
